﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using AutoMapper;

namespace Steve.EFDataLayer
{
    [Export(typeof(ContentTypeRepository))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    public class EFContentTypeRepository : ContentTypeRepository
    {
        static EFContentTypeRepository()
        {
            SteveEFDataLayer.SetupAutoMapper();
        }

        protected override IEnumerable<ContentType> GetContentTypesCore()
        {
            using (var ctx = new SteveEntities())
            {
                var query = from ct in ctx.DbContentTypes
                            select ct;

                return query.ToList().Select(db => Mapper.Map<DbContentType, ContentType>(db)).ToList();
            }
        }
    }
}
